﻿using System;
using System.Linq;
using System.Web.Mvc;
using Capacitacion.Models;

namespace Capacitacion.Controllers
{
    public class HomeController : Controller
    {
        readonly RestaurantsContext _context = new RestaurantsContext();
        public ActionResult QuickSearch(string result)
        {
            var restaurants = _context.Restaurants
                            .Where(r => r.Name.Contains(result))
                            .Take(10)
                            .Select(r => new { label = r.Name });
            return Json(restaurants, JsonRequestBehavior.AllowGet);
        }

        public PartialViewResult Search(string result)
        {
            var restaurants = _context.Restaurants
                .Where(r => r.Name.Contains(result) ||
                        String.IsNullOrEmpty(result))
                .Take(10);
            return PartialView("_RestaurantSearchResults", restaurants);
        }

        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to my App!";
            ViewBag.MSG = "Interact with this apps";
            ViewBag.Searchtxt = "Search your favourite restaurant:";

            return View();
        }

        public ActionResult About()
        {
            return View();
        }
    }
}
